<template>
  <div class='withdrawReviewDialog'>
    <el-dialog
      title="提现审核"
      :visible.sync="isShow"
      width="40%"
      center
      :before-close="handleClose">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
        <el-form-item label="审核状态" prop="status">
          <el-select v-model="ruleForm.status" placeholder="请选择审核状态">
            <el-option label="通过" value="1"></el-option>
            <el-option label="驳回" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核意见" prop="check_opinion">
          <el-input type="textarea" v-model="ruleForm.check_opinion"></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="submit('ruleForm')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    return {
      isShow: false,
      ruleForm: {
        id: null,
        status: '',
        check_opinion: ''
      },
      rules: {
        status: [
          { required: true, message: '请选择审核状态', trigger: 'change' }
        ]
      }
    }
  },
  methods: {
    show (pData) {
      this.isShow = true
      this.ruleForm.id = pData.id
    },
    submit (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.submitPost()
          this.isShow = false
        } else {
          return false
        }
      });
    },
    submitPost () {
      let params = {
        id: this.ruleForm.id,
        status: this.ruleForm.status
      }
      if (this.ruleForm.check_opinion != '') {
        params.check_opinion = this.ruleForm.check_opinion
      }

      this.$axios.put('api/drawing', params).then(res => {
        if (res.data.code == 200) {
          this.$message({
            type: 'success',
            message: "审核成功！"
          })
          this.$emit('refresh')
          this.handleClose()
        } else if (res.data.code == 400) {
          this.$message.error(res.data.message)
        }
      }).catch(err => {

      })
    },
    handleClose () {
      this.$refs['ruleForm'].resetFields()
      this.isShow = false
    }
  }
}
</script>

<style lang='less' type='text/css'>
  .withdrawReviewDialog {
    .el-select {
      width: 100%;
    }
  }
</style>
